<?php
/*!
Application_Model_Login
REQUIRES db.php

*/

require("db.php");

class Application_Model_Login {
	
	public function userExists($username, $password) 
	{
		//! Returns true if parameters(username, password) == database(username,password).\n
		
    	$qstring = "SELECT * FROM users";
		$result = mysql_query($qstring);
		
		while ($row = mysql_fetch_assoc($result)) {
			if ($username == $row['user'] && $password == $row['password']) {
				return true;
			}
		}
		
		return false;
	}
	
	public function getRole($username) 
	{
		//! Returns user role.\n
		
    	$qstring = "SELECT * FROM users WHERE user = \"" . $username . "\"";
		$result = mysql_query($qstring);
		
		while ($row = mysql_fetch_assoc($result)) {
			if ($username == $row['user']) {
				return $row['role'];
			}
		}
		
		return null;
	}
}
